﻿@model ShoppingCartModel
@using Nop.Core
@using Nop.Core.Infrastructure
@using Nop.Web.Models.ShoppingCart;
@{
    var webHelper = EngineContext.Current.Resolve<IWebHelper>();
}
<div class="">
    @Html.Widget("order_summary_content_before")
    <div class="row">
        <div class="col-sm-12">
            @Html.Partial("_OrderReviewData", Model.OrderReviewData)
        </div>
    </div>
         
    
   
    @if (Model.Items.Count > 0)
    {
        if (Model.Warnings.Count > 0)
        {
            <div class="alert alert-danger square-box ">
            
                @for (int i = 0; i < Model.Warnings.Count; i++)
                {
                    <div>@Model.Warnings[i]</div>
                }
            
            </div>
        }
@*we add enctype = "multipart/form-data" because "File upload" attribute control type requries it*@
        using (Html.BeginRouteForm("ShoppingCart", FormMethod.Post, new { enctype = "multipart/form-data" }))
        {
            <div class="custom-page-box-border-less-div">
                <div id="cart_items">
    

                    <div class="table-responsive cart_info">
                        <table class="table table-condensed custom-shopping-cart-page">
                            <thead>
                                <tr class="cart_menu">
                                    @if (Model.IsEditable)
                                    {
                                        <th class="tbl">
                                            @T("ShoppingCart.Remove")
                                        </th>
                                    }
                                    @if (Model.ShowSku)
                                    {
                                        <th class="tbl" >
                                            @T("ShoppingCart.SKU")
                                        </th>
                                    }
                                    @if (Model.ShowProductImages)
                                    {
                                        <th class="picture tbl "></th>
                                    }
                                    <th class="tbl">
                                        @T("ShoppingCart.Product(s)")
                                    </th>
                                    <th class="tbl">
                                        @T("ShoppingCart.UnitPrice")
                                    </th>
                                    <th class="tbl">
                                        @T("ShoppingCart.Quantity")
                                    </th>
                                    <th class="end tbl">
                                        @T("ShoppingCart.ItemTotal")
                                    </th>
                                </tr>

                            </thead>
                            <tbody>
                                @foreach (var item in Model.Items)
                                {
                                    <tr class="border-row">
                                        @if (Model.IsEditable)
                                        {
                                            <td class="remove-from-cart">
                                                <input type="checkbox" name="removefromcart" value="@(item.Id)" />
                                            </td>
                                        }
                                        @if (Model.ShowSku)
                                        {
                                            <td class="">
                                       
                                                <input name="" type="text" value="@(item.Sku)" class="square-box inheri-width sku"  />

                                            </td>
                                        }
                                        @if (Model.ShowProductImages)
                                        {
                                            <td class="product-picture">
                                                <img alt="@item.Picture.AlternateText" src="@item.Picture.ImageUrl" title="@item.Picture.Title" />
                                            </td>
                                        }
                                        <td class="product">
                                            <a href="@Url.RouteUrl("Product", new { SeName = item.ProductSeName })" class="product-name">@item.ProductName</a>
                                            @if (!String.IsNullOrEmpty(item.AttributeInfo))
                                            {
                                                <div class="attributes">
                                                    @Html.Raw(item.AttributeInfo)
                                                </div>
                                            }
                                            @if (!String.IsNullOrEmpty(item.RecurringInfo))
                                            {
                                                <div class="recurring-info">
                                                    @Html.Raw(item.RecurringInfo)
                                                </div>
                                            }
                                            @if (Model.IsEditable && item.AllowItemEditing)
                                            {
                                                var editCartItemUrl = Url.RouteUrl("Product", new {SeName = item.ProductSeName});
                                                editCartItemUrl = webHelper.ModifyQueryString(editCartItemUrl, "updatecartitemid=" + item.Id, null);
                                                <div class="edit-item">
                                                    <a class="btn btn-primary get" href="@editCartItemUrl">@T("Common.Edit")</a>
                                                </div>
                                            }
                                            @if (item.Warnings.Count > 0)
                                            {
                                
                                                <div class="alert alert-danger square-box">
                                                    @for (int i = 0; i < item.Warnings.Count; i++)
                                                    {
                                                        <div>@item.Warnings[i]</div>
                                                    }
                                                </div>
                                
                                            }
                                        </td>
                                        <td class="unit-price nobr">
                                            <span class="product-unit-price">@item.UnitPrice</span>
                                        </td>
                                        <td class="qty nobr">
                                            @if (Model.IsEditable)
                                            {
                                                if (item.AllowedQuantities.Count > 0)
                                                {
                                                    <select name="itemquantity@(item.Id)" class=" square-box">
                                                        @foreach (var qty in item.AllowedQuantities)
                                                        {
                                                            <option selected="@qty.Selected" value="@qty.Value">@qty.Value</option>
                                                        }
                                                    </select>
                                                }
                                                else
                                                {
                                                    <input name="itemquantity@(item.Id)" type="text" value="@(item.Quantity)" class="fo square-box inheri-width quan"  />
                                                }

                                            }
                                            else
                                            {
                                                <span>@item.Quantity</span>
                                            }
                                        </td>
                                        <td class="">
                                            <span class="crt-total text-right">@item.SubTotal</span>
                                            @if (!String.IsNullOrEmpty(item.Discount))
                                            {
                                                <div class="discount">
                                                    @T("ShoppingCart.ItemYouSave"): @item.Discount
                                                </div>
                                            }
                                        </td>
                            
                                
                                    </tr>
                            
                                }
                            </tbody>
                        </table>
                    </div>

                </div>
            </div>


            <div class="custom-cart-div">
                
            
           
                @if (!String.IsNullOrEmpty(Model.CheckoutAttributeInfo))
                {
                <div class="selected-checkout-attributes">
                    @Html.Raw(Model.CheckoutAttributeInfo)
                </div>
                }
                <div class="buttons">
                    @if (Model.IsEditable)
                    {
                        <div class="common-buttons">
                            <input type="submit" name="updatecart" value="@T("ShoppingCart.UpdateCart")" class="btn btn-primary get pull-left" />
                            <input type="submit" name="continueshopping" value="@T("ShoppingCart.ContinueShopping")" class="btn btn-primary get pull-right" />
                        </div>
                        @Html.Partial("_CheckoutAttributes", Model.CheckoutAttributes, new ViewDataDictionary())
                    }
                </div>
            </div>
            <div class="space15px">
                
            </div><div class="space15px">
                
            </div><div class="space15px">
                
            </div>
            <div class="custom-page-box-border-less-div">
                
                
                @if (Model.IsEditable)
                {
                    if (!String.IsNullOrEmpty(Model.MinOrderSubtotalWarning))
                    {
                        <div>
                            <div class="alert alert-danger square-box min-amount-warning">
                                @Model.MinOrderSubtotalWarning
                            </div>
                        </div>
                    }
                }
                <div class="row">
                    @if (Model.IsEditable)
                    {
                                
                        <div class="col-md-4 ">
                            <div class="custom-footer-cart-div">
                                @Html.Partial("_DiscountBox", Model.DiscountBox)
                                @Html.Partial("_GiftCardBox", Model.GiftCardBox)
                                @Html.Widget("order_summary_content_deals")
                            </div>
                        </div>
                        <div class="col-md-4 ">
                            
                                @Html.Partial("EstimateShipping", Model.EstimateShipping)    
                            
                            
                        </div>
                                
                    }
                    <div class="col-md-4 pull-right">
                        <div class="custom-footer-cart-div">
                            @Html.Action("OrderTotals", "ShoppingCart", new { isEditable = Model.IsEditable })
                            @if (Model.IsEditable)
                            {
                                if (Model.TermsOfServiceOnShoppingCartPage)
                                {
                                    <div id="terms-of-service-warning-box" title="@T("Checkout.TermsOfService")" style="display:none;">
                                        <p>@T("Checkout.TermsOfService.PleaseAccept")</p>
                                    </div><br/>
                                    <div class="terms-of-service">
                                        <input id="termsofservice" type="checkbox" name="termsofservice" />
                                        @T("Checkout.TermsOfService.IAccept")
                                        <span class="read" onclick="javascript:OpenWindow('@Url.RouteUrl("TopicPopup", new { SystemName = "conditionsofUse" })', 450, 500, true)"><a>@T("Checkout.TermsOfService.Read")</a></span>
                                    </div><br/>
                                }
                                <div class="checkout-buttons">
                                    @if (String.IsNullOrEmpty(Model.MinOrderSubtotalWarning))
                                    {
                                        <script type="text/javascript">
                                            $(document).ready(function () {
                                                $('#checkout').click(function () {
                                                    //terms of service
                                                    var termOfServiceOk = true;
                                                    if ($('#termsofservice').length > 0) {
                                                        //terms of service element exists
                                                        if (!$('#termsofservice').is(':checked')) {
                                                            $("#terms-of-service-warning-box").dialog();
                                                            termOfServiceOk = false;
                                                        } else {
                                                            termOfServiceOk = true;
                                                        }
                                                    }
                                                    return termOfServiceOk;
                                                });
                                            });
                                        </script>
                                        <button type="submit" id="checkout" name="checkout" value="checkout" class="btn btn-primary get">
                                            <span>@T("Checkout.Button")</span>
                                        </button>
                                    }
                                </div>
                                <div class="addon-buttons">
                                    @*Payment method buttons (e.g. GoogleCheckoutButton, Paypal Express)*@
                                    @Html.Partial("_ButtonPaymentMethod", Model)
                                </div>
                            }
                        </div>
                    </div>
                </div>
            </div>

            if (Model.IsEditable)
            {
                @Html.Action("CrossSellProducts", "Product")
            }
        }
    }
    else
    {   <div class="custom-page-box-div">
             @T("ShoppingCart.CartIsEmpty")
        </div>
       
    }
    @Html.Widget("order_summary_content_after")
</div>

